# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=libyang
pkgver=2.1.148
pkgrel=1
pkgdesc="YANG data modelling language parser and toolkit"
url="https://github.com/CESNET/libyang"
arch="all"
license="BSD-3-Clause-Clear"
makedepends="
	bison
	cmake
	cmocka-dev
	expect
	flex
	pcre2-dev
	samurai
	"
checkdepends="bash"
subpackages="$pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/CESNET/libyang/archive/v$pkgver.tar.gz"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CFLAGS="$CFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DENABLE_TESTS="$(want_check && echo ON || echo OFF)" \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	local skip="yanglint.*"
	case "$CARCH" in
	s390x)
		# fails
		local skip="$skip|utest_structure"
		;;
	esac

	ctest --output-on-failure --test-dir build -E "$skip"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
548628e6879f37cd27b0b39197a389c140b4372d11309f588ab93a4d74889b59f891f5b6bc447b491e24544559a42e93a1dbfa49827506aed30b226cf61ca400  libyang-2.1.148.tar.gz
"
